package laf.socf.simulator.gui;

import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.io.Serializable;
import java.util.Observer;
import java.util.Vector;
import javax.swing.JPanel;

/**
 *
 * @author L.A. Fernando
 */
public class SimContext extends JPanel implements Serializable,
        MouseMotionListener {

    private Vector<Robot> robots = new Vector<Robot>();
    private Vector<Artifact> artifacts = new Vector<Artifact>();
    private Robot selectedRobot = null;
    private transient Observer observer = null;
    private int brickX, brickY;

    public int getBrickX() {
        return brickX;
    }

    public void setBrickX(int brickX) {
        this.brickX = brickX;
    }

    public int getBrickY() {
        return brickY;
    }

    public void setBrickY(int brickY) {
        this.brickY = brickY;
    }

    public Robot getSelectedRobot() {
        return selectedRobot;
    }

    public Vector<Artifact> getArtifacts() {
        return artifacts;
    }

    public void setArtifacts(Vector<Artifact> artifacts) {
        this.artifacts = artifacts;
    }

    public Vector<Robot> getRobots() {
        return robots;
    }

    public void setRobots(Vector<Robot> robots) {
        this.robots = robots;
    }

    public Observer getObserver() {
        return observer;
    }

    public void setObserver(Observer observer) {
        this.observer = observer;
    }

    public SimContext() {
        this.setBackground(Color.lightGray);
        this.setLayout(null);
        this.addMouseMotionListener(this);
    }

    public void mouseMoved(MouseEvent e) {
        this.observer.update(null, e.getPoint());
    }

    public void mouseDragged(MouseEvent e) {
        this.observer.update(null, e.getPoint());
    }

    public void addRobot(Robot robot) {
        this.robots.add(robot);
        this.artifacts.add(robot);
        this.add(robot);
    }

    public void addBrick(BrickWall brick) {
        this.artifacts.add(brick);
        this.add(brick);
    }

    public void addMine(Mine mine) {
        this.artifacts.add(mine);
        this.add(mine);
    }

    public void setSelectedRobot(Robot selectedRobot) {
        this.selectedRobot = selectedRobot;
        this.getObserver().update(null, "Current Selected Robot: " + this.selectedRobot.toString());
    }

    public void startRobots() {
        for (Robot r : this.getRobots()) {
            r.startSensors();
        }
    }

    public void stopRobots() {
        for (Robot r : this.getRobots()) {
            r.stopSensors();
        }
    }

}
